package com.zhaopin.file;

import org.apache.commons.io.FileUtils;
import org.junit.Test;

import javax.validation.constraints.Past;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.*;

/**
 * @author Administrator
 * @create 2021-04-21 14:19
 */
public class FileReaderTest {

    @Test
    public void testRead() throws IOException {

        List<String> listPr = new ArrayList();
        List<String> listPs = new ArrayList();
        List list = FileUtils.readLines(new File("E:\\BaiduNetdiskDownload\\文档\\文本\\1111.txt"), Charset.defaultCharset());
        boolean flag = false;
        for (int i = 0; i < list.size(); i++) {
            String str = list.get(i).toString();
            if (str.startsWith("prapi")) {

            } else if (str.startsWith("psapi")) {
                flag = true;
            } else {
                //prapi的
                if (!flag) {
                    if (str.startsWith("\"")) {
                        listPr.add(str);
                    }
                } else {
                    //psapi的
                    if (str.startsWith("\"")) {
                        listPs.add(str);
                    }
                }
            }
        }
        Map<String, String> map = new HashMap<>();
        for (String str : listPr) {
            String[] strAttr = str.split(" ");
            if (map.containsKey(strAttr[1])) {
                map.put(strAttr[1], map.get(strAttr[1]) + " " + strAttr[0]);
            } else {
                map.put(strAttr[1], strAttr[0]);
            }

        }
        for (String str : listPs) {
            String[] strAttr = str.split(" ");
            if (map.containsKey(strAttr[1])) {
                map.put(strAttr[1], map.get(strAttr[1]) + " " + strAttr[0]);
            } else {
                map.put(strAttr[1], strAttr[0]);
            }
        }

        for (Map.Entry<String, String> stringStringEntry : map.entrySet()) {
            System.out.println(stringStringEntry.getKey() + " : " + stringStringEntry.getValue());
        }
    }

    @Test
    public void testRead2() throws IOException {

        List list = FileUtils.readLines(new File("E:\\BaiduNetdiskDownload\\文档\\文本\\1111.txt"), Charset.defaultCharset());
        Set<String> seth  = new HashSet<>();
        Set<String> setn  = new HashSet<>();
        for (Object o : list) {
            String s = (String)o;
            if(s.endsWith("h")){
                seth.add(s);
            }
            if(s.endsWith("n")){
                setn.add(s);
            }
        }
        for (String s : seth) {
            System.out.println(s);
        }
        System.out.println("----------------------------------------");
        for (String s : setn) {
            System.out.println(s);
        }

    }
    @Test
    public void testRead3() throws IOException {

        List list1 = FileUtils.readLines(new File("E:\\BaiduNetdiskDownload\\文档\\文本\\new 1.txt"), Charset.defaultCharset());
        List list2 = FileUtils.readLines(new File("E:\\BaiduNetdiskDownload\\文档\\文本\\new 2.txt"), Charset.defaultCharset());

        for (int i = 0; i < list1.size(); i++) {
            if (!list2.contains(list1.get(i))) {
                System.out.println("在2中而不在1中: " + list1.get(i));
            }
        }

        for (int i = 0; i < list2.size(); i++) {
            if(!list1.contains(list2.get(i))){
                System.out.println("在2中而不在1中: " + list2.get(i));
            }
        }


    }


}
